RTC Registers
/* Name : main.c * Purpose : Source code for RTC Interfacing with ARM LPC1248. * Author : Gemicates * Date : 2018-16-02 * Website : www.gemicates.org * Revision : None */ #include<lpc21xx.h> // header file for LPC21XX series #define rs (1<<24) // register select pin #define rw (1<<25) // read write pin #define en (1<<26) // enable pin void delay(int j ) // Time delay function in milli seconds { int i; for(;j;j--) for(i=6000;i;i--); } void data_lcd(char ch) // Function to send data to LCD { int i =0; i = ch; i = i<<16; IOPIN1 &=(0XFF00FFFF); IOPIN1 |= i; IOSET1 = rs; IOCLR1 = rw; IOSET1 = en; delay(2); IOCLR1 = en; } void cmd_lcd(char ch) // Function to send command to LCD { int i =0; i = ch; i = i<<16; IOPIN1 &=(0XFF00FFFF); IOPIN1 |= i; IOCLR1 = rs; IOCLR1 = rw; IOSET1 = en; delay(2); IOCLR1 = en; } void init_lcd() // Funtion to Initialize LCD { cmd_lcd(0x38); // for using 8-bit 2 row mode and 5x7 Dots of LCD cmd_lcd(0x01); // clear screen cmd_lcd(0x06); // display ON cmd_lcd(0x0c); // force cursor to beginning of second row cmd_lcd(0x80); // clear screen } void str_lcd(char *str) // Function to display it in LCD { while(*str) data_lcd(*str++); } void time(void) // function to perfom the operation of clock { cmd_lcd(0x80); str_lcd("HH:MM:SS"); cmd_lcd(0xc0); data_lcd(48+(HOUR/10)); data_lcd(48+(HOUR%10)); data_lcd(':'); data_lcd(48+(MIN/10)); data_lcd(48+(MIN%10)); data_lcd(':'); data_lcd(48+(SEC/10)); data_lcd(48+(SEC%10)); } void SetTime(void) // function to initialize RTC { CCR = 0x02; HOUR = 0; MIN = 0; SEC = 0; CCR = 0x11; } int main(void) { SetTime(); PINSEL2 = 0X00000000; // select PORT1 as GPIO mode IODIR1 = 0XFFFFFFFF; // make PORT1 pin as Output mode init_lcd(); while (1) // Repeat(loop) forever { time(); } }